package com.the_ring.behavior.state;

import java.util.HashMap;
import java.util.Map;

/**
 * @author: t22306139
 * @date: 2023/12/1  14:52
 */
public class StateHandler implements State{

    public static final Map<String, State> stateMap = new HashMap<>();

    public static StateEnum initState() {
        return StateEnum.A;
    }

    public StateHandler() throws InstantiationException, IllegalAccessException {
        for (StateEnum stateEnum : StateEnum.values()) {
            stateMap.put(stateEnum.name(), stateEnum.getClazz().newInstance());
        }
    }

    @Override
    public void stateA2B(StateContext context) {
        State state = stateMap.get(context.getCurrent().name());
        state.stateA2B(context);
    }

    @Override
    public void stateB2C(StateContext context) {
        State state = stateMap.get(context.getCurrent().name());
        state.stateB2C(context);
    }

    @Override
    public void stateC2B(StateContext context) {
        State state = stateMap.get(context.getCurrent().name());
        state.stateC2B(context);
    }
}
